//
//  BrowModelController.m
//  Weibo
//
//  Created by taoshanchang on 15/2/2.
//  Copyright (c) 2015年 taoshanchang. All rights reserved.
//

#import "BrowModelController.h"
#import "CONSTS.h"

@interface BrowModelController ()

@end

@implementation BrowModelController

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if(self){
        
        self.title = @"图片浏览模式";
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self _initView];
}

-(void)_initView{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-20) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableView delegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    if(indexPath.row == 0){
        cell.textLabel.text = @"大图";
        cell.detailTextLabel.text = @"所有网络加载大图";
    }else if(indexPath.row == 1){
        cell.textLabel.text = @"小图";
        cell.detailTextLabel.text = @"所有网络加载小图";
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    int model = -1;
    
    if(indexPath.row ==0){
        model = LargBrowModel;
    }else if(indexPath.row){
        model = SmallBrowModel;
    }
    //将模式保存到本地
    [[NSUserDefaults standardUserDefaults] setInteger:model forKey:kBrowModel];
    [[NSUserDefaults standardUserDefaults] synchronize];
    //刷新微博列表通知
    [[NSNotificationCenter defaultCenter] postNotificationName:kReloadTableNotification object:nil];
    
    [self.navigationController popViewControllerAnimated:YES];
}

@end
